<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
// ------------------------------------------------------------------------

/**
 * Category_model class
 *
 * This class abstracts functions for the request categories
 *
 * @package		Photoggle
 * @subpackage	Models
 * @category	Models
 * @author		Russ
 */
class Category_model extends CI_Model {

	/* Category behavior */
	var $table_name = 'a_achievement_categories';
	var $id   = '';
	var $name = '';

	function __construct()
	{
		parent::__construct();
	}
        
   /**
	* Find valid id for category name then get the data for that category
	*
	* @param	string
	* @return	object
	*/
	function get_category_id($categoryName)
	{
		$sql = " SELECT * FROM a_achievement_categories WHERE name LIKE '" . $categoryName . "'";
		$query = $this->db->query($sql);
		if($query->num_rows() == 1)
		{
			return $query->row()->id;
		}
		return NULL;
	}
        
    /**
	 * Fetch all category titles:
         *
	 *
	 * @access	public
	 * @return	array
	 */
	function get_categories()
	{
		$sql = "
				SELECT
                                        a_achievement_categories.id         AS id,
                                        a_achievement_categories.name       AS title
				FROM
					a_achievement_categories
				ORDER BY 
					a_achievement_categories.id
				";
		$query = $this->db->query($sql);
		return $query->result();
	}

 }
 ?>